* SOUND-BITE JOURNALISM & PUBLIC ARGUMENT - Analytical Code*

* Author: Eike Mark Rinke (University of Mannheim)
* This Version: 6 June 16

/*Note: Make sure to change working directory (using -cd- cmd) to folder containing
	data before running code.*/

version 14
set more off
capture log close
log using JoC_2016_SoundBites, replace

* Read in data
use JoC_2016_SoundBites_Data, clear

*** Logistic random intercept models of opinion justification ***

* M0: Empty model
	/* Note: Restricted to utterances in political news items (polittopic==1). 
	Later models are restricted to	political news without this if condition b/c
	some covariates only measured for political news items. */
melogit justbin if polittopic==1 || broadcastID: || itemID: , intpoints(7)
estat icc	// calculate item- and broadcast level ICCs
estat ic	// calculate LL and AIC
display e(ll) * -2	// calculate -2LL


*** H1: Utterance duration main effect on justification
* M1
melogit justbin i.country i.orgtype ///
i.ittypebin i.decrelbin i.oppos ///
i.cenperspeak i.metadel i.R1_bin ///
utdur ///
|| broadcastID: || itemID: , intpoints(7)
estat ic	// calculate LL and AIC
display e(ll) * -2	// calculate -2LL
margins, dydx(utdur) predict(mu fixedonly) // calculate AME of utterance duration

	* Figure 1, Plot a.: Plot main effect of utterance duration
margins, at(utdur=(5(5)60)) predict(mu fixedonly)	// calculate predictive margins
marginsplot, title("a. Overall", size(large)) plotopts(lwidth(thin)) ///
recastci(rarea) level(95) ci1opts(fcolor(gs12) lcolor(gs12)) ///
recast(line) ///
xtitle("Opinion utterance duration (sec)", height(5)) xlabel(10(10)60) ///
yscale(r(0 1)) ylabel(0(.2)1, angle(horizontal)) ytitle("P(Justification)") ///
name(utdurall, replace) scheme(s1mono)
graph close utdurall

*** H2: Utterance duration  x speaker type interaction effect on justification
* M2
	/*Note: Variable cenperspeak replaced by alternative speaker type indicator
	(jouspeak).*/
melogit justbin i.country i.orgtype ///
i.ittypebin i.decrelbin i.oppos ///
i.metadel i.R1_bin ///
i.jouspeak##c.utdur_c ///
|| broadcastID: || itemID: , intpoints(7)
estat ic	// calculate LL and AIC
display e(ll) * -2	// calculate -2LL
	
margins, dydx(jouspeak) predict(mu fixedonly) // calculate AME of speaker type
margins, dydx(utdur) predict(mu fixedonly) // calculate AME of utterance duration
margins, dydx(utdur) at(jouspeak=(0 1)) predict(mu fixedonly) // calculate AME of utterance duration x speaker type interaction term
display .0028181 - .0102054	 // interaction AME = (AME journalist) - (AME non-journalist)

	* Figure 1, Plot b.: Plot interaction effect of utterance duration and speaker type
margins jouspeak, at(utdur=(5(5)60)) predict(mu fixedonly)
marginsplot, title("b. Non-journalists vs. journalists", size(large)) ///
plot1opts(lwidth(thin)) ///
recastci(rarea) level(95) ci1opts(fcolor(gs12) lcolor(gs12)) ///
ci2opts(fcolor(gs12) lcolor(gs12)) ///
recast(line) ///
xtitle("Opinion utterance duration (sec)", height(5)) xlabel(10(10)60) ///
yscale(r(0 1)) ylabel(0(.2)1, angle(horizontal)) ytitle("P(Justification)") ///
plot2opts(lpattern(shortdash) lwidth(thin)) ///
legend(rows(2) size(3) nobox region(margin(vsmall) ///
lwidth(none)) position(11) ring(0)) ///
name(utdurXjouspeak, replace) scheme(s1mono)
graph close utdurXjouspeak

* Figure 1: Combine Plots a. and b.
graph combine utdurall utdurXjouspeak, ycommon graphregion(color(white))	// graph of utterance duration effects overall and by speaker type
graph save JoC_2016_SoundBites_Data_Fig1, replace
graph close


* Endnote 6: M2 respecified as main effect model (w/o interaction term)
melogit justbin i.country i.orgtype ///
i.ittypebin i.decrelbin i.oppos ///
i.metadel i.R1_bin ///
i.jouspeak c.utdur_c ///
|| broadcastID: || itemID: , intpoints(7)
	
margins, dydx(jouspeak) predict(mu fixedonly) // calculate AME of speaker type


*** M1: Cross-national robustness checks

* Figure 2, Plot a.: M1 (DE only)
	/* Note: Restricted to German (country==2),	non-journalist (jouspeak==0) and
	primary/direct utterances (utcat==1)*/
melogit justbin i.orgtype ///
i.ittypebin i.decrelbin i.oppos ///
i.cenperspeak i.metadel i.R1_bin ///
utdur ///
if country==2 & jouspeak==0 & utcat==1 || broadcastID: || itemID: , intpoints(7)

	* Plot main effect of utterance duration (DE only)
	/* Note: Out-of-range values of CIs trimmed for graphing*/
margins, at(utdur=(5(5)60)) predict(mu fixedonly) level(95) ///
saving(JoC_2016_SoundBites_Data_Fig2a, replace) // saves output including estimates

use JoC_2016_SoundBites_Data_Fig2a, clear
label variable _at8 "Utterance duration (sec)"
replace _ci_lb = 0 if _ci_lb < 0	// trim lower CI bound < 0 to 0
replace _ci_ub = 1 if _ci_ub > 1	// trim upper CI bound > 0 to 1

graph twoway (rarea _ci_lb _ci_ub _at8, fcolor(gs12) lcolor(gs12)) ///
(connect _margin _at8, lpattern(solid) lwidth(thin) msymbol(none)), ///
title("a. Germany", size(large)) xtitle("Opinion utterance duration (sec)", height(5)) xlabel(10(10)60) ///
yscale(r(0 1)) ylabel(0(.2)1, angle(horizontal)) ytitle("P(Justification)") ///
legend(off) name(utdurnjouDE, replace) scheme(s1mono)
graph close utdurnjouDE

use JoC_2016_SoundBites_Data, clear

* Figure 2, Plot b.: M1 (RU only)
	/* Note: Restricted to Russian (country==3), non-journalist (jouspeak==0) and
	primary/direct utterances (utcat==1)*/
melogit justbin i.orgtype ///
i.ittypebin i.decrelbin i.oppos ///
i.cenperspeak i.metadel i.R1_bin ///
utdur ///
if country==3 & jouspeak==0 & utcat==1 || broadcastID: || itemID: , intpoints(7)

	* Plot main effect of utterance duration (RU only)
margins, at(utdur=(5(5)60)) predict(mu fixedonly) level(95) ///
saving(JoC_2016_SoundBites_Data_Fig2b, replace) // saves output including estimates

use JoC_2016_SoundBites_Data_Fig2b, clear
label variable _at8 "Utterance duration (sec)"
replace _ci_lb = 0 if _ci_lb < 0	// trim lower CI bound < 0 to 0
replace _ci_ub = 1 if _ci_ub > 1	// trim upper CI bound > 0 to 1

graph twoway (rarea _ci_lb _ci_ub _at8, fcolor(gs12) lcolor(gs12)) ///
(connect _margin _at8, lpattern(solid) lwidth(thin) msymbol(none)), ///
title("b. Russia", size(large)) xtitle("Opinion utterance duration (sec)", height(5)) xlabel(10(10)60) ///
yscale(r(0 1)) ylabel(0(.2)1, angle(horizontal)) ytitle("P(Justification)") ///
legend(off) name(utdurnjouRU, replace) scheme(s1mono)
graph close utdurnjouRU

use JoC_2016_SoundBites_Data, clear

* Figure 2, Plot c.: M1 (US only)
	/* Note: Restricted to US (country==1),	non-journalist (jouspeak==0) and
	primary/direct utterances (utcat==1)*/
melogit justbin i.orgtype ///
i.ittypebin i.decrelbin i.oppos ///
i.cenperspeak i.metadel i.R1_bin ///
utdur ///
if country==1 & jouspeak==0 & utcat==1 || broadcastID: || itemID: , intpoints(7)

	* Plot main effect of utterance duration (US only)
margins, at(utdur=(5(5)60)) predict(mu fixedonly) level(95)	// calculate predictive margins
marginsplot, title("c. United States", size(large)) plotopts(lwidth(thin)) ///
recastci(rarea) level(95) ci1opts(fcolor(gs12) lcolor(gs12)) ///
recast(line) ///
xtitle("Opinion utterance duration (sec)", height(5)) xlabel(10(10)60) ///
yscale(r(0 1)) ylabel(0(.2)1, angle(horizontal)) ytitle("P(Justification)") ///
name(utdurnjouUS, replace) scheme(s1mono)
graph close utdurnjouUS

* Figure 2: Combine Plots a.-c.
graph combine utdurnjouDE utdurnjouRU utdurnjouUS, ycommon rows(2) graphregion(color(white)) // graph of utterance duration effects, by country
graph save JoC_2016_SoundBites_Data_Fig2, replace
graph close

* Call Figure 1 & Figure 2
graph use JoC_2016_SoundBites_Data_Fig1
graph use JoC_2016_SoundBites_Data_Fig2

log close
exit
